<?php

if(!defined('IN_JANSEN')) {
    exit('Access Denied');
}

function getMyParam($param, $method='pg') {
    global $$param;
    if ( $method == 'pg' && ( isset($_POST[$param]) || isset($_GET[$param]) ) ) {
        $$param = ( isset($_POST[$param]) ) ? $_POST[$param] : $_GET[$param];
    }
    if ( $method == 'p' && isset($_POST[$param]) ) {
        $$param = $_POST[$param];
    }
    if ( $method == 'g' && isset($_GET[$param]) ) {
        $$param = $_GET[$param];
    }
    if ( $method == 'c' && isset($_COOKIE[$param]) ) {
        $$param = $_COOKIE[$param];
    }
    if ( $method == 's' && isset($_SESSION[$param]) ) {
        $$param = $_SESSION[$param];
    }
    if ( $method == 'r' && isset($_REQUEST[$param]) ) {
        $$param = $_REQUEST[$param];
    }
    if ( $method == 'f' && isset($_FILES[$param]) ) {
        $$param = $_FILES[$param];
    }
}

function daddslashes($string, $force = 0) {
    if(!$GLOBALS['magic_quotes_gpc'] || $force) {
        if(is_array($string)) {
            foreach($string as $key => $val) {
                $string[$key] = daddslashes($val, $force);
            }
        } else {
            $string = addslashes($string);
        }
    }
    return $string;
}

function dexit($message = '') {
    echo $message;
    //output();
    exit();
}

function debuginfo() {
    if($GLOBALS['debug']) {
        global $db, $starttime, $debuginfo, $debug_out;
        $mtime = explode(' ', microtime());
        $debuginfo = array('time' => number_format(($mtime[1] + $mtime[0] - $starttime), 6), 'queries' => $db->querynum);
        $debug_out = "Processed in " . $debuginfo['time'] . " second(s), " . $debuginfo['queries'] . " queries";
        return TRUE;
    } else {
        return FALSE;
    }
}

function Cookie($ck_Var,$ck_Value,$ck_Time='F'){
    global $cookietime,$cookiedomain,$cookiepath;
    if($ck_Time=='F') $ck_Time = $cookietime;
    $S=$_SERVER['SERVER_PORT']=='443' ? 1:0;
    setCookie($ck_Var,$ck_Value,$ck_Time,$cookiepath,$cookiedomain,$S);
}

function GetCookie($Var){
    if (isset($_COOKIE[$Var])) {
        return $_COOKIE[$Var];
    } else {
        return false;
    }
}

function getUnixTime($in_time) {
    //2000-01-01 10:00
    if (preg_match("/^([\d]{4})-([\d]{2})-([\d]{2})\s([\d]{2}):([\d]{2})$/i", $in_time, $match_array)) {
        return mktime($match_array[4], $match_array[5], 0, $match_array[2], $match_array[3], $match_array[1]);
    } else {
        return false;
    }
}

function getUnixTime2($in_time) {
    //2000-01-01
    if (preg_match("/^([\d]{4})-([\d]{1,2})-([\d]{1,2})$/i", $in_time, $match_array)) {
        return mktime(0, 0, 0, $match_array[2], $match_array[3], $match_array[1]);
    } else {
        return false;
    }
}

function PrintEot($template,$EXT="htm"){
    global $tplpath;
    if(!$template) $template='N';
    $path=JANSEN_ROOT."templates/$tplpath/$template.$EXT";
    !file_exists($path) && $path=JANSEN_ROOT."templates/default/$template.$EXT";
//debug($path);
    return $path;
}

function PrintPrint($template,$EXT="htm"){
    global $tplpath;
    if(!$template) $template='N';
    $path=JANSEN_ROOT."templates/print/$template.$EXT";
    //!file_exists($path) && $path=JANSEN_ROOT."templates/default/$template.$EXT";
    return $path;
}

function readover($filename,$method="rb"){
    strpos($filename,'..')!==false && exit('Forbidden');
    if($handle=@fopen($filename,$method)){
        flock($handle,LOCK_SH);
        $filedata=@fread($handle,filesize($filename));
        fclose($handle);
    }
    return $filedata;
}

function writeover($filename,$data,$method="rb+",$iflock=1,$check=1,$chmod=1){
    $check && strpos($filename,'..')!==false && exit('Forbidden');
    touch($filename);
    $handle=fopen($filename,$method);
    if($iflock){
        flock($handle,LOCK_EX);
    }
    fwrite($handle,$data);
    if($method=="rb+") ftruncate($handle,strlen($data));
    fclose($handle);
    $chmod && @chmod($filename,0777);
}

function delPicture($file_name) {
    $file_path = JANSEN_ROOT . 'attachments/' . $file_name;
    if (file_exists($file_path)) {
        //@chmod($filename,0777);
        @unlink($file_path);
    }
}

function delSystemPicture($file_name) {
    $file_path = JANSEN_ROOT . 'attachments/system/' . $file_name;
    if (file_exists($file_path)) {
        //@chmod($filename,0777);
        @unlink($file_path);
    }
}

function ispage($number) {
    return !empty($number) && preg_match ("/^([0-9]+)$/", $number);
}

function getPageStr($total, $page, $perpage, $link) {
    $pages = @ceil($total / $perpage);
    $pagelink = '';
    if ($pages == 1) {
        $pagelink = "";
        return "";
    } elseif ($page == 1 && $page<$pages) {
        $pagelink = '<a href="' . $link . 'page=' . ($page+1) . '">></a> <a href="' . $link . 'page=' . $pages . '">>></a>';
    } elseif ($page<$pages) {
        $pagelink = '<a href="' . $link . 'page=1"><<</a> <a href="' . $link . 'page=' . ($page-1) . '"><</a> <a href="' . $link . 'page=' . ($page+1) . '">></a> <a href="' . $link . 'page=' . $pages . '">>></a>';
    } elseif ($page == $pages) {
        $pagelink = '<a href="' . $link . 'page=1"><<</a> <a href="' . $link . 'page=' . ($page-1) . '"><</a>';
    }

    $final_num = $page*$perpage < $total ? $page*$perpage : $total;
    return '<table width=100% align=center border=0 cellspacing=0 cellpadding=0 height=24>
              <tr>
                <td align=left>&nbsp;' . (($page-1)*$perpage+1) . ' - ' . $final_num . ' of ' . $total . ' records</td>
                <td align=right>&nbsp;&nbsp;&nbsp;' . $pagelink . '&nbsp;</td>
              </tr>
            </table>';
}

function getPhotoPageStr($total, $page, $perpage, $link, $show="items", $ext="") {
    $pages = @ceil($total / $perpage);
    $pagelink = '';

    $page_str = "<span class='text_big2'>&nbsp;&nbsp;|&nbsp;$page&nbsp;|&nbsp;&nbsp;</span>";
    $final_num = $page*$perpage < $total ? $page*$perpage : $total;
    
    $str = 'Viewing ' . $show . ' <strong>' . (($page-1)*$perpage+1) . '</strong> - <strong>' . $final_num . '</strong> of  <strong>' . $total . '</strong> ' . $ext . ' .';
    if ($pages == 1 && $page==$pages) {//echo $str;exit;
        $pagelink = "";
        return array('str'=>$str, 'pagelink'=>$page_str);
    } elseif ($page == 1 && $page<$pages) {
        $pagelink = $page_str . '&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . ($page+1) . '"><span class="text_big">></span></a>&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . $pages . '"><span class="text_big">>></span></a>';
    } elseif ($page<$pages) {
        $pagelink = '<a href="' . $link . 'page=1"><span class="text_big"><<</span></a>&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . ($page-1) . '"><span class="text_big"><</span></a>&nbsp;&nbsp;&nbsp;' . $page_str . '&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . ($page+1) . '"><span class="text_big">></span></a>&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . $pages . '"><span class="text_big">>></span></a>';
    } elseif ($page == $pages) {
        $pagelink = '<a href="' . $link . 'page=1"><span class="text_big"><<</span></a>&nbsp;&nbsp;&nbsp;<a href="' . $link . 'page=' . ($page-1) . '"><span class="text_big"><</span></a>&nbsp;&nbsp;&nbsp;' . $page_str;
    }


    //$str = (($page-1)*$perpage+1) . ' - ' . $final_num . ' of ' . $total . ' records&nbsp;&nbsp;' . $pagelink;
    return array('str'=>$str, 'pagelink'=>$pagelink);
}

function setSystemValue($key, $value) {
    global $db;
    $sql = "UPDATE `system` SET `value` = '$value', `uptime` = '" . time() . "' WHERE name='$key'";
    $db->query($sql);

    updateCache('system');
}

function getSystemValue($name) {
    global $cachedir, $db, $cache_updatetime, $timestamp;
    $_SYSTEM = array();

    $file_name = JANSEN_ROOT . $cachedir . "/system_cache.php";
    if (!file_exists($file_name) || $timestamp-@filemtime($file_name) > $cache_updatetime*60) {
        updateCache('system');
    }

    require_once($file_name);
    if ($name == "") {
        return $_SYSTEM;
    } elseif (!isset($_SYSTEM[$name])) {
        return false;
    } else {
        return $_SYSTEM[$name];
    }
}


function updateCache($name) {
    global $cachedir, $db;

    $file_name = JANSEN_ROOT . $cachedir . "/system_cache.php";

    $sql = "SELECT `name`, `value` FROM `system`";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $out_ary[] = $rs;
    }

    $tmp_str = "";

    foreach ($out_ary as $v) {
        $tmp_str .= "\$_SYSTEM['" . $v['name'] . "'] = '" . $v['value'] . "';\r\n";
    }
    $tmp_str = "<?php\r\n" . $tmp_str . "?>";

    writeover($file_name, $tmp_str);
}

function checkLogin() {
    global $jansen_uid, $jansen_type, $jansen_status, $login_time, $timestamp, $cookietime;
    //echo $jansen_uid ;echo "<br>"; 
    //echo $jansen_type > 0;echo "<br>"; 
    //echo time() - $login_time;
    if ($jansen_uid > 0 && $jansen_type > 0 && time() - $login_time <= 1800) {
        Cookie("jansenuser",base64_encode($jansen_uid."\t".$jansen_type."\t".$jansen_status."\t".$timestamp), $cookietime); 
        
    } else {
    	Cookie('jansenuser','',0);
        header("Location:login.php");
        exit;
    }
}

function getUserPrice($type) {
    return 'price_1';
}

function getPrice($jansen_type1, $inventorytype1, $price_ary, $sp) {
    //echo $jansen_type1 . "<hr>" . $inventorytype1;echo "<pre>";print_r($price_ary);
    if ($jansen_type1 == 1) {
        if ($inventorytype1 == 0) {
            return $price_ary['price_3'];
        } else {
            return $sp == 0 ? $price_ary['price_3'] : $sp;
        }

    } elseif ($jansen_type1 == 2) {
        if ($inventorytype1 == 0) {
            return $price_ary['price_2'] == 0 ? $price_ary['price_1'] : $price_ary['price_2'];
        } elseif ($inventorytype1 == 1) {
            return $sp == 0 ? $price_ary['price_1'] : $sp;
        } elseif ($inventorytype1 == 2) {
            return $sp == 0 ? $price_ary['price_2'] : $sp;
        }
    }

    return false;

}

function sendmail($from_name,$from_email,$to_name,$to_email,$subject,$content){
    
    if (strstr($to_email, ",")) {
        $tmp_ary = explode(",", $to_email);
        foreach ($tmp_ary as $v) {
            $tmp_ary2[] = "$to_name <$v>";
        }
        $to = implode(",", $tmp_ary2);

    } else {
        $to   = "$to_name <$to_email>";
    }
    
 
		$from     =   "MIME-Version:   1.0\n";   
		$from   .=   "Content-type:   text/html;   charset=utf-8\n";
		$from   .=   "From: $from_name <$from_email>";


    @mail($to,$subject,$content,$from) or die("<h2 align=\"center\">Something must wrong, please contact the webmaster.</h2>");

}

function sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content){
    //$to_email => name1@domain.com,name2@domain.com;
    if (strstr($to_email, ",")) {
        $tmp_ary = explode(",", $to_email);
        foreach ($tmp_ary as $v) {
            $tmp_ary2[] = "$to_name <$v>";
        }
        $to = implode(",", $tmp_ary2);

    } else {
        $to   = "$to_name <$to_email>";
    }

    //͵ʼ
    $mime = "From: $from_name <$from_email>\nX-Mailer:PHP\nX-Priority:2\nContent-Type: text/html; charset=iso-8859-1\nContent-Transfer-Encoding: 7bit\nMIME-Version: 1.0";
    @mail($to,$subject,$content,$mime) or die("<h2 align=\"center\">Something must wrong, please contact the webmaster.</h2>");

}

function getExt($filename) {
    if (strstr($filename, ".")) {
        $tmp_ary = explode(".", $filename);
        return array_pop($tmp_ary);
        //return substr(strrchr($file, "."), 1);
    }

    return false;
}

function setStatus($flag) {
    global $jansen_type, $page_title, $page_guide_pic, $menu_id, $special_flag, $sql_2, $sql_3, $page_guide_name,$page_guide_name2,$page_special_pic;
    $special_flag=$sql_2='';
    $sql_3=' AND i.`inventory_id` = n.`id` ';


    if ($flag) {
        $page_title = 'jans2en furniture - Specials - Specials';
        $page_guide_name = 'Specials';
        $page_guide_name2 = '<a href="inventory.php?special=1">Specials</a>';
        $page_guide_pic = $page_special_pic;
        $menu_id = 8;
        $special_flag = '&special=1';
        $sql_2 = ' AND i.`special_price`>0 ';
        $sql_3 = ' AND i.`inventory_id` = n.`id` ';

        if ($jansen_type==2) {
            $sql_2 = ' AND i.`special_price`>0 ';
        } elseif ($jansen_type == 1) {
            $sql_2 = ' AND i.`special_price2`>0 ';
        }
    }
}


function br2br($str, $add, $len) {
    if (strlen($str) > $len) {
        $str1 = substr($str, 0, $len);
        $str2 = substr($str, $len, 1);
        $str3 = substr($str, $len+1);
       // /*
        //var_dump($str1); echo "<hr>";
        //var_dump($str2);echo "<hr>";
        //var_dump($str3);echo "<hr>";
        //exit;
       // */
        if ($str2 != " " && $str2 != " ") {
            $str4 = substr(strrchr($str1, " "), 1);
            //var_dump($str4);exit;
            if (!$str4) {
                return $str1 . $add . $str2 . $str3;
            } else {
                return str_replace($str4, $add . $str4, $str1) . $str2 . $str3;
            }
            //exit;
        } else {
            //if (substr($str, $len-1, 1) == '&') {
                //return $str1 . "<br>" . $add . $str3;
            //} else {
                return $str1 . $add . $str3;
            //}
        }
    } else {
        return $str;
    }
}

// תΪ ent2ncr 
function ent2ncr($text) {
    $to_ncr = array(
    '&quot;' => '&#34;',
    '&amp;' => '&#38;',
    '&frasl;' => '&#47;',
    '&lt;' => '&#60;',
    '&gt;' => '&#62;',
    '|' => '&#124;',
    '&nbsp;' => '&#160;',
    '&iexcl;' => '&#161;',
    '&cent;' => '&#162;',
    '&pound;' => '&#163;',
    '&curren;' => '&#164;',
    '&yen;' => '&#165;',
    '&brvbar;' => '&#166;',
    '&brkbar;' => '&#166;',
    '&sect;' => '&#167;',
    '&uml;' => '&#168;',
    '&die;' => '&#168;',
    '&copy;' => '&#169;',
    '&ordf;' => '&#170;',
    '&laquo;' => '&#171;',
    '&not;' => '&#172;',
    '&shy;' => '&#173;',
    '&reg;' => '&#174;',
    '&macr;' => '&#175;',
    '&hibar;' => '&#175;',
    '&deg;' => '&#176;',
    '&plusmn;' => '&#177;',
    '&sup2;' => '&#178;',
    '&sup3;' => '&#179;',
    '&acute;' => '&#180;',
    '&micro;' => '&#181;',
    '&para;' => '&#182;',
    '&middot;' => '&#183;',
    '&cedil;' => '&#184;',
    '&sup1;' => '&#185;',
    '&ordm;' => '&#186;',
    '&raquo;' => '&#187;',
    '&frac14;' => '&#188;',
    '&frac12;' => '&#189;',
    '&frac34;' => '&#190;',
    '&iquest;' => '&#191;',
    '&Agrave;' => '&#192;',
    '&Aacute;' => '&#193;',
    '&Acirc;' => '&#194;',
    '&Atilde;' => '&#195;',
    '&Auml;' => '&#196;',
    '&Aring;' => '&#197;',
    '&AElig;' => '&#198;',
    '&Ccedil;' => '&#199;',
    '&Egrave;' => '&#200;',
    '&Eacute;' => '&#201;',
    '&Ecirc;' => '&#202;',
    '&Euml;' => '&#203;',
    '&Igrave;' => '&#204;',
    '&Iacute;' => '&#205;',
    '&Icirc;' => '&#206;',
    '&Iuml;' => '&#207;',
    '&ETH;' => '&#208;',
    '&Ntilde;' => '&#209;',
    '&Ograve;' => '&#210;',
    '&Oacute;' => '&#211;',
    '&Ocirc;' => '&#212;',
    '&Otilde;' => '&#213;',
    '&Ouml;' => '&#214;',
    '&times;' => '&#215;',
    '&Oslash;' => '&#216;',
    '&Ugrave;' => '&#217;',
    '&Uacute;' => '&#218;',
    '&Ucirc;' => '&#219;',
    '&Uuml;' => '&#220;',
    '&Yacute;' => '&#221;',
    '&THORN;' => '&#222;',
    '&szlig;' => '&#223;',
    '&agrave;' => '&#224;',
    '&aacute;' => '&#225;',
    '&acirc;' => '&#226;',
    '&atilde;' => '&#227;',
    '&auml;' => '&#228;',
    '&aring;' => '&#229;',
    '&aelig;' => '&#230;',
    '&ccedil;' => '&#231;',
    '&egrave;' => '&#232;',
    '&eacute;' => '&#233;',
    '&ecirc;' => '&#234;',
    '&euml;' => '&#235;',
    '&igrave;' => '&#236;',
    '&iacute;' => '&#237;',
    '&icirc;' => '&#238;',
    '&iuml;' => '&#239;',
    '&eth;' => '&#240;',
    '&ntilde;' => '&#241;',
    '&ograve;' => '&#242;',
    '&oacute;' => '&#243;',
    '&ocirc;' => '&#244;',
    '&otilde;' => '&#245;',
    '&ouml;' => '&#246;',
    '&divide;' => '&#247;',
    '&oslash;' => '&#248;',
    '&ugrave;' => '&#249;',
    '&uacute;' => '&#250;',
    '&ucirc;' => '&#251;',
    '&uuml;' => '&#252;',
    '&yacute;' => '&#253;',
    '&thorn;' => '&#254;',
    '&yuml;' => '&#255;',
    '&OElig;' => '&#338;',
    '&oelig;' => '&#339;',
    '&Scaron;' => '&#352;',
    '&scaron;' => '&#353;',
    '&Yuml;' => '&#376;',
    '&fnof;' => '&#402;',
    '&circ;' => '&#710;',
    '&tilde;' => '&#732;',
    '&Alpha;' => '&#913;',
    '&Beta;' => '&#914;',
    '&Gamma;' => '&#915;',
    '&Delta;' => '&#916;',
    '&Epsilon;' => '&#917;',
    '&Zeta;' => '&#918;',
    '&Eta;' => '&#919;',
    '&Theta;' => '&#920;',
    '&Iota;' => '&#921;',
    '&Kappa;' => '&#922;',
    '&Lambda;' => '&#923;',
    '&Mu;' => '&#924;',
    '&Nu;' => '&#925;',
    '&Xi;' => '&#926;',
    '&Omicron;' => '&#927;',
    '&Pi;' => '&#928;',
    '&Rho;' => '&#929;',
    '&Sigma;' => '&#931;',
    '&Tau;' => '&#932;',
    '&Upsilon;' => '&#933;',
    '&Phi;' => '&#934;',
    '&Chi;' => '&#935;',
    '&Psi;' => '&#936;',
    '&Omega;' => '&#937;',
    '&alpha;' => '&#945;',
    '&beta;' => '&#946;',
    '&gamma;' => '&#947;',
    '&delta;' => '&#948;',
    '&epsilon;' => '&#949;',
    '&zeta;' => '&#950;',
    '&eta;' => '&#951;',
    '&theta;' => '&#952;',
    '&iota;' => '&#953;',
    '&kappa;' => '&#954;',
    '&lambda;' => '&#955;',
    '&mu;' => '&#956;',
    '&nu;' => '&#957;',
    '&xi;' => '&#958;',
    '&omicron;' => '&#959;',
    '&pi;' => '&#960;',
    '&rho;' => '&#961;',
    '&sigmaf;' => '&#962;',
    '&sigma;' => '&#963;',
    '&tau;' => '&#964;',
    '&upsilon;' => '&#965;',
    '&phi;' => '&#966;',
    '&chi;' => '&#967;',
    '&psi;' => '&#968;',
    '&omega;' => '&#969;',
    '&thetasym;' => '&#977;',
    '&upsih;' => '&#978;',
    '&piv;' => '&#982;',
    '&ensp;' => '&#8194;',
    '&emsp;' => '&#8195;',
    '&thinsp;' => '&#8201;',
    '&zwnj;' => '&#8204;',
    '&zwj;' => '&#8205;',
    '&lrm;' => '&#8206;',
    '&rlm;' => '&#8207;',
    '&ndash;' => '&#8211;',
    '&mdash;' => '&#8212;',
    '&lsquo;' => '&#8216;',
    '&rsquo;' => '&#8217;',
    '&sbquo;' => '&#8218;',
    '&ldquo;' => '&#8220;',
    '&rdquo;' => '&#8221;',
    '&bdquo;' => '&#8222;',
    '&dagger;' => '&#8224;',
    '&Dagger;' => '&#8225;',
    '&bull;' => '&#8226;',
    '&hellip;' => '&#8230;',
    '&permil;' => '&#8240;',
    '&prime;' => '&#8242;',
    '&Prime;' => '&#8243;',
    '&lsaquo;' => '&#8249;',
    '&rsaquo;' => '&#8250;',
    '&oline;' => '&#8254;',
    '&frasl;' => '&#8260;',
    '&euro;' => '&#8364;',
    '&image;' => '&#8465;',
    '&weierp;' => '&#8472;',
    '&real;' => '&#8476;',
    '&trade;' => '&#8482;',
    '&alefsym;' => '&#8501;',
    '&crarr;' => '&#8629;',
    '&lArr;' => '&#8656;',
    '&uArr;' => '&#8657;',
    '&rArr;' => '&#8658;',
    '&dArr;' => '&#8659;',
    '&hArr;' => '&#8660;',
    '&forall;' => '&#8704;',
    '&part;' => '&#8706;',
    '&exist;' => '&#8707;',
    '&empty;' => '&#8709;',
    '&nabla;' => '&#8711;',
    '&isin;' => '&#8712;',
    '&notin;' => '&#8713;',
    '&ni;' => '&#8715;',
    '&prod;' => '&#8719;',
    '&sum;' => '&#8721;',
    '&minus;' => '&#8722;',
    '&lowast;' => '&#8727;',
    '&radic;' => '&#8730;',
    '&prop;' => '&#8733;',
    '&infin;' => '&#8734;',
    '&ang;' => '&#8736;',
    '&and;' => '&#8743;',
    '&or;' => '&#8744;',
    '&cap;' => '&#8745;',
    '&cup;' => '&#8746;',
    '&int;' => '&#8747;',
    '&there4;' => '&#8756;',
    '&sim;' => '&#8764;',
    '&cong;' => '&#8773;',
    '&asymp;' => '&#8776;',
    '&ne;' => '&#8800;',
    '&equiv;' => '&#8801;',
    '&le;' => '&#8804;',
    '&ge;' => '&#8805;',
    '&sub;' => '&#8834;',
    '&sup;' => '&#8835;',
    '&nsub;' => '&#8836;',
    '&sube;' => '&#8838;',
    '&supe;' => '&#8839;',
    '&oplus;' => '&#8853;',
    '&otimes;' => '&#8855;',
    '&perp;' => '&#8869;',
    '&sdot;' => '&#8901;',
    '&lceil;' => '&#8968;',
    '&rceil;' => '&#8969;',
    '&lfloor;' => '&#8970;',
    '&rfloor;' => '&#8971;',
    '&lang;' => '&#9001;',
    '&rang;' => '&#9002;',
    '&larr;' => '&#8592;',
    '&uarr;' => '&#8593;',
    '&rarr;' => '&#8594;',
    '&darr;' => '&#8595;',
    '&harr;' => '&#8596;',
    '&loz;' => '&#9674;',
    '&spades;' => '&#9824;',
    '&clubs;' => '&#9827;',
    '&hearts;' => '&#9829;',
    '&diams;' => '&#9830;'
    );

    return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
}

// ¼ûʵҳϢ
function browseTracking($action, $aid=0, $details, $settime = '600') {
    /*
    * action: $browse_tracking_ary = array(1=>'Login', 2=>'About us', 3=>'Products', 4=>'Inventory', 5=>'Tradeshow', 6=>'Search', 7=>'Gallery');
    * aid: ӦactionactionΪ3ʱ¼ʱĲƷid
    * details: Ϣ
    * date: ʱ
    * settime: ¼ͬһĬ600m
    */
    global $db, $timestamp, $jansen_uid;
    
    if (isset($jansen_uid) && $jansen_uid>0) {
        
        if ($action == 6) {
            $sql = "select id from browse_tracking where `uid`='$jansen_uid' and `action`='$action' and `aid`='$aid' and `details`='$details' and `date`>($timestamp-$settime)";
        } else {
            $sql = "select id from browse_tracking where `details`='$details' and `uid`='$jansen_uid' and `action`='$action' and `aid`='$aid' and `date`>($timestamp-$settime)";
        }
        $row = $db->get_one($sql);
        if (empty($row)) {
            $sql = "insert into browse_tracking (`uid`, `action`, `aid`, `details`, `date`) values ('$jansen_uid', '$action', '$aid', '$details', '$timestamp')";
            @$db->query($sql);
        }     
    } 
}

// ¼ûʵ¼Ϣ
function browseTracking_login($jansen_uid) {

    global $db, $timestamp;
    
    if ($jansen_uid>0) {
        
        $sql = "select id from browse_tracking where `uid`='$jansen_uid' and `action`='1' and `aid`='0' and `date`>($timestamp-600)";
        $row = $db->get_one($sql);
        if (empty($row)) {
            $sql = "insert into browse_tracking (`uid`, `action`, `aid`, `details`, `date`) values ('$jansen_uid', '1', '0', 'Login', '$timestamp')";
            @$db->query($sql);
        }
    }
}


function saveCart($db, $jansen_uid, $cart) {
	global $timestamp;

	if ($jansen_uid>0) {
		if (!empty($cart)) {

			$sql = "SELECT cart FROM cart_record WHERE `uid`='$jansen_uid'";
			$cart_info_ary = $db->get_one($sql);
			if (empty($cart_info_ary) || empty($cart_info_ary['cart'])) {
				$sql2 = "SELECT * FROM `user` WHERE `id`='$jansen_uid'";
				$user_info_ary = $db->get_one($sql2);
				$dealer_name = trim($user_info_ary['lastname']) != '' ? $user_info_ary['firstname'] . ' ' . $user_info_ary['lastname'] : $user_info_ary['firstname'];
				
				$system_ary = getSystemValue("");
				$webmaster_name = $system_ary['webmaster_name'];
				$webmaster_email = $system_ary['webmaster_email'];

				// ʼ
				require_once './mail/alert_order_to_webmaster.php';    
				//echo $content;exit;
				
				sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);

			}

			$cart_r = serialize($cart);
			$sql = "replace into cart_record (`uid`, `cart`, `date`) values ('$jansen_uid', '" . $cart_r . "', '$timestamp')";
		} else {
			$sql = "replace into cart_record (`uid`, `cart`, `date`) values ('$jansen_uid', '', '$timestamp')";
		}
        @$db->query($sql);
	}
}


?>